package competition;

import java.util.Scanner;

/**
 * Author: 笨蛋超人不会飞
 * Date:  9:36
 */
public class c_02 {
    public static void main(String[] args) {
        int n;
//        通过终端输入的方式，读取输入的一个整数，将值赋给n
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int start;
        int end;
        for (int i = 0; i < n; i++) {
//            通过输入的方式来赋值给start和end
            start = sc.nextInt();
            end = sc.nextInt();
            if((start+end)%7==0){
                System.out.println(7);
            }else {
                int temp=(start+end)%7;
                System.out.println(temp);
            }
        }

    }
}
